{extend name="inherit/form" /}

{block name="title"}编辑问题{/block}

{block name="form"}
<style>
    .layui-form-item .layui-input-inline {
        width: 350px;
    }
</style>
{/block}

{block name="content"}
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin"
    style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">分类</label>
        <div class="layui-input-inline">
            <div id="demo1" class="xm-select-demo"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">问题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" value="{$data.title}" lay-verify="required" lay-verType="tips"
                placeholder="请输入问题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">回复</label>
        <div class="layui-input-inline">
            <textarea name="answer" lay-verify="required" lay-verType="tips" placeholder="请输入问题回复"
                class="layui-textarea">{$data.answer}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
            <input type="number" name="sort" value="{$data.sort}" lay-verify="required" lay-verType="tips"
                placeholder="请输入排序值, 值越大越靠前" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="显示" {$data.status==1 ? 'checked' : '' }>
            <input type="radio" name="status" value="0" title="隐藏" {$data.status==0 ? 'checked' : '' }>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="hidden" name="id" value="{$data.id}">
        <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
    </div>
</div>
{/block}

{block name="foot"}
<script src="__admin__/xm-select/xm-select.js"></script>

<script>
    layui.config({
        base: '__layuiadmin__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        , request: 'plugin/request'
    }).use(['index', 'form', 'request'], function () {
        var $ = layui.$
            , form = layui.form
            , request = layui.request;

        var demo1 = xmSelect.render({
            el: '#demo1',
            radio: true,
            clickClose: true,
            tips: '请选择问题分类',
            name: 'classify_id',
            layVerify: 'required',
            layVerType: 'tips',
            prop: {
                name: 'name',
                value: 'id',
            },
            data: []
        })

        let url = request.url("{:u('selectClassify')}", {
            id: "{$data.classify_id}"
        })

        $.ajax({
            method: 'get',
            url: url,
        }).then(response => {
            console.log(response)
            demo1.update({
                data: response.data,
                autoRow: true,
            })
        });
    })
</script>
{/block}